package com.charles.seckillData.feignFallBack;

import com.charles.seckillData.domain.SysUser;
import com.charles.seckillData.feignService.RemoteUserService;
import com.charles.seckillData.model.UserLogin;
import com.charles.seckillComponentCommon.domain.R;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * @author Charles-H
 * 
 * 负载均衡客户业务降级处理
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService> {
    
    private static final Logger LOGGER = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);
    
    @Override
    public RemoteUserService create(Throwable cause) {
        
        LOGGER.error("客户服务调用失败:{}", cause.getMessage());
        
        return new RemoteUserService() {
            @Override
            public R<UserLogin> queryUserInfoByUserCard(String userCard, String source) {
                return R.fail("客户服务调用失败:" + cause.getMessage());
            }

            @Override
            public R<Boolean> registerUser(SysUser sysUser, String source) {
                return R.fail("客户服务调用失败:" + cause.getMessage());
            }
        };
    }
}
